package anthology.daily_question._24_11;

import java.util.Arrays;

//https://leetcode.cn/problems/find-the-power-of-k-size-subarrays-ii/description/?envType=daily-question&envId=2024-11-07
public class _3255长度为K的子数组的能量值2{
    //统计长度
    class Solution {
        public int[] resultsArray(int[] nums, int k) {
            int n = nums.length;
            int[] ans = new int[n - k + 1];
            Arrays.fill(ans, -1);
            int cnt = 0;
            for (int i = 0; i < n; i++) {
                if(i ==0 || nums[i] - nums[i - 1] != 1)
                    cnt = 1;
                else
                    cnt++;
                if(cnt >= k)
                    ans[i-k+1] = nums[i];
            }
            return ans;
        }
    }


}
